Micron Document

Buffer
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Buffer is an API that provides file-like read/write operations over a channel, enabling stream-like bidirectional transfer of binary data with automatic BZ2 compression.



Usage

With RNS:

# Create a buffer over a link's channel
channel = link.get_channel()
buffer = RNS.Buffer.create_bidirectional_buffer(0, 0, channel, ready_callback)
# Write data
buffer.write("hello, world".encode("utf-8"))
buffer.flush()
# Read data in callback
def ready_callback(ready_bytes: int):
data = buffer.read(ready_bytes)

For a more comprehensive use case, see the Buffer example in the manual.

Reticulum concepts
Buffer